/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.repository;

import me.zhengjie.business.domain.FixedCosts;
import me.zhengjie.business.domain.Fymx;
import me.zhengjie.business.domain.Jzdj;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://el-admin.vip
* @author xiahongbo
* @date 2022-08-17
**/
public interface FymxRepository extends JpaRepository<Fymx, Long>, JpaSpecificationExecutor<Fymx> {


    /**
     * 根据就诊ID查询住院人员的日消费总金额
     * @param jzid /
     * @return /
     */
    @Query(value = "select  " +
            "sum(t.bis_fymx_zj) content , " +
            "to_char(to_date(t.bis_fymx_kfrq, 'yyyy-mm-dd'), 'yyyy-mm-dd')  kfrq " +
            "from bis_fymx t where t.bis_fymx_jzdj_id=?1 " +
            "group by to_char(to_date(t.bis_fymx_kfrq, 'yyyy-mm-dd'), 'yyyy-mm-dd')",nativeQuery = true)
    List<Object> groupByKfrq2Zj(Long jzid);

    /**
     * 费用明细，校验开方日期的床位费
     * @param jzid
     * @param kfrq
     * @return
     */
    @Query(value = "select to_char(wm_concat(to_char(t.bis_fymx_yyypbm)))  from bis_fymx t  " +
            "where t.bis_fymx_jzdj_id=?1 and t.bis_fymx_kfrq=?2 ",nativeQuery = true)
    String queryCw(Long jzid, String kfrq);



}